package com.ctshk.app.order.tour.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.AppReq;
import com.ctshk.common.req.pay.NotifyConsumeReq;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.tour.dto.*;
import com.ctshk.rpc.order.tour.dto.client.ClientOrderDetailsDTO;
import com.ctshk.rpc.order.tour.req.RemainCheckReq;
import com.ctshk.rpc.order.tour.req.SeriesOrderCalculationReq;
import com.ctshk.rpc.order.tour.req.SingleRoomCalculateReq;
import com.ctshk.rpc.order.tour.req.TripIsExistReq;
import com.ctshk.rpc.order.tour.req.client.ClientOrderCancelReq;
import com.ctshk.rpc.order.tour.req.client.ClientOrderInfoReq;
import com.ctshk.rpc.order.tour.req.client.ClientSeriesOrderAddReq;
import com.ctshk.rpc.order.tour.service.ISeriesOrderService;
import com.ctshk.rpc.order.tour.service.ISeriesOrderTouristInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 系列团订单 H5前端控制器
 * </p>
 *
 * @author 谭响
 * @since 2021-01-18
 */
@Slf4j
@Api(value = "系列团订单-APP-H5&App", tags = "系列团订单-APP-H5&App")
@RestController
@RequestMapping("/series/order/h5")
public class SeriesOrderH5Controller extends BaseController {

    @Autowired
    private ISeriesOrderService iSeriesOrderService;

    @Autowired
    private ISeriesOrderTouristInfoService iSeriesOrderTouristInfoService;

    @ApiOperation(value = "获取房间数范围", notes = "获取房间数范围")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "获取房间数范围", operDesc = "获取房间数范围")
    @PostMapping("/calculate")
    public Result<SingleRoomCalculateDTO> calculate(@RequestBody @Valid SingleRoomCalculateReq req) {
        return iSeriesOrderTouristInfoService.calculate(req);
    }

    @ApiOperation(value = "计算单房差", notes = "计算单房差（查看團期-立即报名/追位/留位-预算价格）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.OTHER, operTitle = "查看團期-立即报名/追位/留位-预算价格", operDesc = "查看團期-立即报名/追位/留位-预算价格")
    @PostMapping("/calculation")
    public Result<SeriesOrderCalculationToCDTO> calculation(@RequestBody SeriesOrderCalculationReq req) {
        return iSeriesOrderService.calculationToC(req);
    }

    @ApiOperation(value = "余位校验", notes = "余位校验")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "余位校验", operDesc = "余位校验")
    @PostMapping("/remain-check")
    public Result remainCheck(@RequestBody @Valid RemainCheckReq req) {
        return iSeriesOrderService.remainCheck(req);
    }

    @ApiOperation(value = "下单", notes = "旅游团-下单")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "旅游团-下单", operDesc = "旅游团-下单")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid ClientSeriesOrderAddReq req, @ApiIgnore AppReq appReq) {
        Long userId = getCurrentUserAllowNotLogInUserId();
        req.setUserId(userId);
        return iSeriesOrderService.add(req, appReq);
    }

    @ApiOperation(value = "订单信息", notes = "旅游团-下单-订单信息")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "旅游团-下单-订单信息", operDesc = "旅游团-下单-订单信息")
    @PostMapping("/order-info/{orderId}")
    public Result<OrderInfoDTO> orderInfo(@PathVariable("orderId") Long orderId) {
        return iSeriesOrderService.orderInfo(orderId);
    }

    @ApiOperation(value = "取消订单", notes = "旅游团-取消订单")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "旅游团-取消订单", operDesc = "旅游团-取消订单")
    @PostMapping("/cancel")
    public Result cancel(@RequestBody @Valid ClientOrderCancelReq req) {
        return iSeriesOrderService.cancel2(req);
    }

    @ApiOperation(value = "旅游团-支付结果", notes = "旅游团-支付结果")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "旅游团-支付结果", operDesc = "旅游团-支付结果")
    @GetMapping("/pay-result/{orderId}")
    public Result<SeriesOrderPayDTO> payResult(@PathVariable("orderId") Long orderId) {
        return iSeriesOrderService.payResult(orderId);
    }

    @ApiOperation(value = "旅游团-订单详情", notes = "旅游团-订单详情")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "旅游团-订单详情", operDesc = "旅游团-订单详情")
    @PostMapping("/order-details")
    public Result<ClientOrderDetailsDTO> info(@RequestBody @Valid ClientOrderInfoReq req) {
        return iSeriesOrderService.info(req);
    }

    @ApiOperation(value = "旅游团-订单详情-判断行程详情是否存在", notes = "旅游团-订单详情-判断行程详情是否存在")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "旅游团-订单详情-判断行程详情是否存在", operDesc = "旅游团-订单详情-判断行程详情是否存在")
    @PostMapping("/trip-exist")
    public Result tripIsExist(@RequestBody @Valid TripIsExistReq req) {
        return iSeriesOrderService.tripIsExist(req);
    }

    @ApiOperation(value = "旅游团-订单详情-退款原因", notes = "旅游团-订单详情-退款原因")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "旅游团-订单详情-退款原因", operDesc = "旅游团-订单详情-退款原因")
    @GetMapping("/reason")
    public Result<List<RefundReasonDTO>> RefundReason() {
        return iSeriesOrderService.RefundReason();
    }

}
